import React from 'react';
import { Table } from 'antd';
import { connect } from 'dva';

const KipTable = props => {
  const { type } = props;
  const kpiCount = props[type];
  const columns = [
    { title: '分类', dataIndex: 'type' },
    { title: '目标金额（万元）', dataIndex: 'target' },
    { title: '已完成金额（万元）', dataIndex: 'finish' },
    { title: '完成进度', dataIndex: 'process' },
  ];
  const dataSource = [
    {
      type: '建设',
      target: kpiCount.buildCount,
      finish: kpiCount.buildCompleteCount,
      process: kpiCount.buildCompleteRate,
    },
    {
      type: '保障',
      target: kpiCount.serviceCount,
      finish: kpiCount.serviceCompleteCount,
      process: kpiCount.serviceCompleteRate,
    },
    {
      type: '合计',
      target: kpiCount.totalCount,
      finish: kpiCount.totalCompleteCount,
      process:
        kpiCount.totalCount == 0
          ? 0
          : parseInt((kpiCount.totalCompleteCount / kpiCount.totalCount) * 100),
    },
  ];

  return (
    <Table
      columns={columns}
      dataSource={dataSource}
      pagination={false}
      bordered
      style={{ width: '100%' }}
    />
  );
};
export default connect(state => state.home)(KipTable);
